<?php

function list_spd(){
	my_set_code_js('
		function confirmDelete( i){
		var check = confirm(\'Akan mendelete data? \'); 
		if(check){
			location.href=\'index.php?com='.$_GET['com'].'&task=delete&id=\'+i;
		}
		return;	}
	');
	$header = array(
		'No SPD'=>array('style'=>'border-bottom:2px solid;width:10%'), 
		'nid'=>array('style'=>'text-align:center;border-bottom:2px solid;width:10%'),   
		'nama'=>array('style'=>'border-bottom:2px solid;width:30%'),  
		'Pengajuan'=>array('style'=>'border-bottom:2px solid;width:10%'), 		
		'Durasi'=>array('style'=>'border-bottom:2px solid;width:20%'), 		
		'tujuan'=>array('style'=>'border-bottom:2px solid;width:10%'),  
		' '=>array('style'=>'border-bottom:2px solid;width:10%'), 
	);
	
	$query = "
			SELECT * FROM spd_simple_non_karyawan a 
			INNER JOIN spd_non_karyawan b ON b.non_karyawan_id = a.karyawan_id   
			 ORDER BY a.tanggal_pengajuan DESC 
		";
	$result = my_query($query );
	$total_records = my_num_rows($result );
	$scroll_page =5;  
	$per_page =15;  
	$current_page = isset($_GET['page']) ? (int) $_GET['page'] : 1 ; 
	if($current_page < 1){
		$current_page = 1;
	}		 
	$pager_url  ="index.php?com={$_GET['com']}&task={$_GET['task']}&field={$_GET['field']}&key={$_GET['key']}&page=";	 
	$inactive_page_tag = 'style="padding:4px;background-color:#BBBBBB"';  
	$previous_page_text = ' Mundur '; 
	$next_page_text = ' Maju ';  
	$first_page_text = ' Awal '; 
	$last_page_text = ' Akhir ';
	
	$kgPagerOBJ = new kgPager();
	$kgPagerOBJ->pager_set(
		$pager_url, 
		$total_records, 
		$scroll_page, 
		$per_page, 
		$current_page, 
		$inactive_page_tag, 
		$previous_page_text, 
		$next_page_text, 
		$first_page_text, 
		$last_page_text ,$pager_url_last); 
	 		
	$result = my_query($query ." LIMIT ".$kgPagerOBJ->start.", ".$kgPagerOBJ->per_page); 	
	$row = array(); 
	$i = ($current_page  - 1 ) * 15; 
	while($ey = my_fetch_array($result )){
		$i++;
		$karyawan =  loaddata_karyawan($ey['karyawan_id']);  
		$jabatan =  loaddata_jabatan($karyawan['jabatan_id']);  
		
		$detailproperty = array(
			'href'=>'index.php?com='.$_GET['com'].'&task=detail&id='.$ey['spd_simple_id'],
			'title'=>'Detail','rel'=>'facebox'
		);
		$detail_button = button_icon( 'b_props.png' , $detailproperty  );
		$cetakproperty = array(
			'href'=>'index.php?com='.$_GET['com'].'&task=cetak&id='.$ey['spd_simple_id'],
			'title'=>'Cetak SPD'
		);
		$cetak_button = button_icon( 'b_print.png' , $cetakproperty  );
		
		$deleteproperty = array(
			'href'=>'javascript:; ',
			'onclick'=>'javascript:confirmDelete('.$ey['spd_simple_id'].');',
			'title'=>'Delete'
		);
		$delete_button = button_icon( 'b_drop.png' , $deleteproperty  );
		$row[] = array(
			'nomor'=>position_text_align ($ey['nomor'], 'center'),
			'nik'=>position_text_align( $ey['nid'], 'center'),
			'nama'=> $ey['nama'],    	
			'tanggal_pengajuan'=>date('d-m-Y',strtotime($ey['tanggal_pengajuan'])),			 	 	 	 	 	 	
			'tanggal_mulai'=>date('d/m/y',strtotime($ey['tanggal_mulai'])) .' <b>s/d</b> '. date('d/m/y',strtotime($ey['tanggal_mulai'])) , 
			'tujuan'=>strtoupper($ey['tujuan']), 
			'operasi'=> position_text_align( /* $detail_button .' '.*/$delete_button .' '.$cetak_button, 'right'),  
		);
	}
	
	$datas = table_rows($row); 
	$paging = $kgPagerOBJ ->showPaging();
	$search = '<form method="GET"><input type="hidden" name="com" value="'.$_GET['com'].'" />
	<span style="font:10px verdana"><b>Pencarian cepat</b></span>
	<br/><input type="text"  style="width:200px;" name="key" value="'.(isset($_GET['key']) ? $_GET['key']: "").'" />
	<input class="simple_search" type="submit" value=" CARI " /> </form>';
	$menuontop = array(  
		'Create' => array('onclick'=>'javascript: jQuery.facebox({ ajax: \'index.php?com='.$_GET['com'].'&task=create\' });'),
		'Excel'=>array('onclick'=>'javascript:location.href=\'index.php?com='.$_GET['com'].'&task=excel&key='.$_GET['key'].'\';'),
	);	
	
	$printmenu = additional_menu_on_list( $menuontop, $search);
	return $printmenu .table_builder($header , $datas ,  15 ,false , $paging  );
	
}

function detail_spd($id){
	$view = form_header( "SPD Detail" , "SPD Detail"  );
	
 	$fields = my_get_data_by_id('spd_simple',	'spd_simple_id', $id);
	$karyawan = loaddata_karyawan( $fields['karyawan_id'] );
	$view .= form_field_display( $karyawan['nik'] .'/'.  $karyawan['nama_gelar'] , "Karyawan "  );
	$view .= form_field_display( $fields['nomor']  , "Nomor "  );
	$view .= form_field_display( $fields['tanggal_pengajuan']  , "Tanggal pengajuan "  );
	$view .= form_field_display( date('d-m-Y',strtotime( $fields['tanggal_mulai'] ) ) .' s/d '. date('d-m-Y',strtotime( $fields['tanggal_akhir'] ) ) , "Tanggal perjalanan"  );
	$view .= form_field_display( $fields['tujuan']  , "Tujuan"  );
	$view .= form_field_display( $fields['keperluan']  , "Keperluan"  );
	$view .= form_field_display( $fields['status']  , "Status"  );
	$view .= form_field_display( rp_format( $fields['biaya'] )  , "Total biaya"  );
	$view .= form_footer( );
	return $view;	
}

function perjalanan_exists($karyawan_id , $tanggal){
	$query = "SELECT spd_simple_id FROM spd_simple_non_karyawan 
		WHERE karyawan_id = {$karyawan_id} AND DATE(tanggal_mulai) = DATE('{$tanggal}')";
	$result = my_query($query);
	if(my_num_rows($result) > 0){
		return true;
	}
	return false;
}

function form_spd_validate(){
	$errsubmit = false;
	$err = array();
	
	$karyawan_id = check_personel_by_nid_nama($_POST['nama_karyawan']); 	 
	 
	list($ddb,$mmb,$yyyyb) = explode("-" , $_POST['tanggal_mulai']);
	if ((int) $karyawan_id == 0){
		$errsubmit = true;
		$err[] = "NIK Tidak dikenal";
	}
	
	$test_perjalanan = perjalanan_exists((int) $karyawan_id , $yyyyb.'-'.$mmb.'-'.$ddb);
	if($test_perjalanan){
		$errsubmit = true;
		$err[] = "Data perjalanan sudah ada";		
	}
	
	if( $errsubmit){
		return $err;
	}
	
	return $errsubmit;
}

function check_personel_by_nid_nama($nidnama){
	$nidnama = substr( $nidnama , -6);
	$query = "SELECT non_karyawan_id, nid,nama FROM spd_non_karyawan WHERE nid = '{$nidnama}'  "; 
	$result = my_query($query);
	if( my_num_rows($result) > 0 ){ 
		$row = my_fetch_array($result);
		return $row['non_karyawan_id'];
	}
	return false;
}
function form_spd($id=0){
	my_set_file_js(
		array(
			'components/system/jquery/autocomplete/jquery.autocomplete.js' ,
			'components/system/js/calendar/calendarDateInput.js'
		)
	);
	my_set_file_css(
		array(
			'components/system/jquery/autocomplete/jquery.autocomplete.css' 
		)
	);
	
	my_set_code_js('  
		function findValue(li) {
			if( li == null ) return alert("No match!"); 
			if( !!li.extra ) var sValue = li.extra[0]; 
			else var sValue = li.selectValue;
		}

		function selectItem(li) {
			findValue(li);
		}

		function formatItem(row) {
			return   row[0] ;
		}

		function lookupAjax(){
			var oSuggest = $("#nama_karyawan")[0].autocompleter;
			oSuggest.findValue(); 
			return false;
		}
		$(document).ready(function() {
			$("#nama_karyawan").autocomplete(
				"autocomplete_daftar_nama_spd_non_karyawan.php",
				{
					delay:10,
					minChars:2,
					matchSubset:1,
					matchContains:1,
					cacheLength:5,
					onItemSelect:selectItem,
					onFindValue:findValue,
					formatItem:formatItem,
				//	autoFill:true
				}
			);
		});
	
		function checkName(name){
			$.get("check_karyawan_names.php", { nama: name  },
			function(data){
				if(data ==  \'0\' ){
					alert(\'Nama karyawan \'+ name+\' tidak ditemukan\nHarap diperiksa kembali\');
					$(\'#nama_karyawan\').val(\'\');
					return false;
			} 
			});
		}
	');
	$view = form_header( "SPD Detail" , "SPD Detail"  );
	
 	$fields = my_get_data_by_id('spd_simple',	'spd_simple_id', $id);
	$karyawan = loaddata_karyawan( $fields['karyawan_id'] );
	$nama_karyawan = array(
		'name'=>'nama_karyawan',
		'value'=>( isset($_POST['nama_karyawan'] ) ? $_POST['nama_karyawan'] : $karyawan['nik'].($fields ? '/' : '').$karyawan['nama']  ),
		'id'=>'nama_karyawan' , 
		'type'=>'text',
		'size'=>'45' ,
		'onchange'=>'javascript:checkName(this.value)'
	);
	
	$form_field_nama_karyawan = form_dynamic($nama_karyawan);
	$view .= form_field_display( $form_field_nama_karyawan , "Karyawan "  );

	$ftanggal = 
	$ftanggalm =  
	$ftanggala =  date('d-m-Y');
	if($fields){
		list($yyyytanggal  , $mmtanggal,$ddtanggal   ) = explode("-" ,$fields['tanggal_pengajuan'] );
		list($yyyytanggalm , $mmtanggalm,$ddtanggalm ) = explode("-" ,$fields['tanggal_mulai'] );
		list($yyyytanggala , $mmtanggala,$ddtanggala ) = explode("-" ,$fields['tanggal_akhir'] );
		$ftanggal = $ddtanggal.'-'.$mmtanggal.'-'.$yyyytanggal;
		$ftanggalm = $ddtanggalm.'-'.$mmtanggalm.'-'.$yyyytanggalm;
		$ftanggala = $ddtanggala.'-'.$mmtanggala.'-'.$yyyytanggala;
	}
	
	$tanggal_pengajuan = array(
		'name'=>'tanggal_pengajuan',
		'value'=>(isset($_POST['tanggal_pengajuan'])? $_POST['tanggal_pengajuan'] : $ftanggal),
		'id'=>'tanggal_pengajuan', 
	);
	$form_tanggal_pengajuan = form_calendar($tanggal_pengajuan);
	$view .= form_field_display( $form_tanggal_pengajuan , "Tanggal pengajuan "  );
	
	$tanggal_mulai = array(
		'name'=>'tanggal_mulai',
		'value'=>(isset($_POST['tanggal_mulai'])? $_POST['tanggal_mulai'] : $ftanggalm),
		'id'=>'tanggal_mulai', 
	);
	$form_tanggal_mulai = form_calendar($tanggal_mulai);
	$view .= form_field_display( $form_tanggal_mulai , "Tanggal mulai"  ); 
	
	$tanggal_akhir = array(
		'name'=>'tanggal_akhir',
		'value'=>(isset($_POST['tanggal_akhir'])? $_POST['tanggal_akhir'] : $ftanggala ),
		'id'=>'tanggal_akhir', 
	);
	$form_tanggal_akhir = form_calendar($tanggal_akhir); 
	$view .= form_field_display($form_tanggal_akhir  , "Tanggal akhir"  );
	
	$tujuan = array(
			'name'=>'tujuan',
			'value'=>(isset($_POST['tujuan'])? $_POST['tujuan'] : $fields['tujuan']),
			'id'=>'tujuan' , 
	);
	$form_keperluan = form_dynamic($tujuan);
	$view .= form_field_display( $form_keperluan  , "Tujuan"  );

	$keperluan = array(
			'name'=>'keperluan',
			'value'=>(isset($_POST['keperluan'])? $_POST['keperluan'] : $fields['keperluan']),
			'id'=>'keperluan' ,
			'cols'=>34,
			'rows'=>4
	);
	$form_keperluan = form_textarea($keperluan);
	$view .= form_field_display( $form_keperluan  , "Keperluan"  );
	
	
	$form_antar_pasien = '<input type="radio" name="status" value="Dinas"/> Dinas &nbsp; &nbsp; '; 
	$form_antar_pasien .= '<input type="radio" name="status" value="A/J Pasien"/> A/J Pasien &nbsp; &nbsp; '; 
	$view .= form_field_display( $form_antar_pasien   , "Status dinas" );
 
	$submit = array(
		'value' =>  ' Set Biaya ' ,
		'name' => 'simpan', 
		'type'=>'submit','class'=>'main_button'
	);
	$form_submit= form_dynamic($submit); 
	
	 
	
	$view .= form_field_display( $form_submit    , "&nbsp;" ,  "" );
	$view .= form_footer( );
	return $view; 
}

function delete_spd($id){
	return my_query("DELETE FROM spd_simple_non_karyawan WHERE spd_simple_id = {$id} ");
}

function insert_spd_baru(){
	$karyawan_id = check_personel_by_nid_nama($_POST['nama_karyawan']); 	
	$query = "SELECT MAX(spd_simple_id)+1 AS nji FROM spd_simple_non_karyawan ";
	$result = my_query($query);
	$row 	= my_fetch_array($result);
	$code = date('Ym').sprintf('%04d' , $row['nji']);
	
	list($dda,$mma,$yyyya) = explode("-" , $_POST['tanggal_pengajuan']);
	list($ddb,$mmb,$yyyyb) = explode("-" , $_POST['tanggal_mulai']);
	list($ddc,$mmc,$yyyyc) = explode("-" , $_POST['tanggal_akhir']);
	$tanggal_pengajuan = $yyyya .'-'. $mma . '-' . $dda ;
	$tanggal_mulai = $yyyyb .'-'. $mmb . '-' . $ddb ;
	$tanggal_akhir = $yyyyc .'-'. $mmc . '-' . $ddc ;
	
	$datass = array(
			'nomor'  		=> my_type_data_str($code), 	 	 	 	 	 	 
			'karyawan_id'	=> my_type_data_str($karyawan_id),	 	 	 	 	 	 	
			'tanggal_pengajuan' => my_type_data_str($tanggal_pengajuan),	 	 	 	
			'tanggal_mulai'	=> my_type_data_str( $tanggal_mulai ),	 	
			'tanggal_akhir'	=> my_type_data_str( $tanggal_akhir ), 	
			'tujuan'=> my_type_data_str($_POST['tujuan']), 	 
			'antar_pasien'=> my_type_data_str( isset($_POST['antar_pasien']) ? 'Yes' : 'No'), 	 
			'keperluan' => my_type_data_str($_POST['keperluan'] ),	
			'status' => my_type_data_str($_POST['status'] ),			 	 	 	 	 	 	 
			'biaya'	=> my_type_data_str($_POST['biaya']),
		);
	$spd_id = my_insert_record('spd_simple_non_karyawan',$datass); 
	my_direct('index.php?com='.$_GET['com'].'&task=setbiaya&id='.$spd_id );
}

function excel_report(){
	$periode_id =get_periode_absen();
	$periode = my_get_data_by_id('pr_periode','periode_id',$periode_id);
	$startdate = $periode['dari'];	
	$enddate  = $periode['sampai'];
	$header = array(
		'Sejak'=>array(),  
		'Hingga'=>array(),  
		'NIK'=>array(),  
		'Nama'=>array(),   
		'Status'=>array(),  
		'Tujuan'=>array(),  
		//'Tunjangan'=>array(), 
	);
	
	$query = " SELECT  * FROM   spd_simple_non_karyawan 
			WHERE  ( DATE(tanggal_mulai) BETWEEN '{$startdate}' AND '{$enddate}')
				OR ( DATE(tanggal_akhir) BETWEEN '{$startdate}' AND '{$enddate}')";
 
	$result = my_query($query);
	$row = array();
	while($ey = my_fetch_array($result )){ 
		$karyawan = loaddata_karyawan($ey['karyawan_id']);
		$row[] = array( 
			'sejak'=>  "'".date('d/m/Y',strtotime($ey['tanggal_mulai'])),    
			'hingga'=>  "'".date('d/m/Y',strtotime($ey['tanggal_akhir'])),  
			'nik'=>  "'".$karyawan['nik'],  
			'nama'=>ucfirst($karyawan['nama']),
			'status'=>  $ey['status'], 
			'tujuan'=>  $ey['tujuan'],  
		);
	}
	
	$datas = table_rows_excel($row); 
	return table_builder_excel($header , $datas ,7 ,false ); 	
}

function set_biaya($spd_id){ 
my_set_code_js('
function NilaiRupiah(jumlah) 
{ 
    var titik = ".";
    var nilai = new String(jumlah); 
    var pecah = []; 
    while(nilai.length > 3) 
    { 
        var asd = nilai.substr(nilai.length-3); 
        pecah.unshift(asd); 
        nilai = nilai.substr(0, nilai.length-3); 
    } 
 
    if(nilai.length > 0) { pecah.unshift(nilai); } 
    nilai = pecah.join(titik);
    return nilai; 
} 

$(document).ready(function(){
    $(\'.calc\').change(function(){
        var total = 0;
        $(\'.calc\').each(function(){
            if($(this).val() != \'\')
            {
                total += parseInt($(this).val());
            }
        });
		total_rupiah = NilaiRupiah(total);
        $(\'#total_tunjangan\').html(total_rupiah);
    });
})(jQuery);
');
	$fields = my_get_data_by_id('spd_simple_non_karyawan' , 'spd_simple_id' , $spd_id);
	$karyawan = my_get_data_by_id( 'spd_non_karyawan','non_karyawan_id',$fields['karyawan_id'] ); 
	$jabatan  =  $karyawan['jabatan_non_karyawan'] ;	
	$goljab = my_get_data_by_id('golongan_jabatan','golongan_jabatan_id', (int)$karyawan['golongan_jabatan_id']);

	$view = form_header( "SPD_Detail" , "SPD_Detail"  ); 
	$view .= form_field_display( $karyawan['nik'].'/'.$karyawan['nama']  , "Karyawan "  );
	$view .= form_field_display(   $goljab['kode_golongan_jabatan']  , " Golongan "  );
	$view .= form_field_display( $jabatan  , "Jabatan "  );
	$view .= form_field_display( date('d-m-Y' , strtotime($fields['tanggal_mulai']) ) .' <b>s/d</b> '. date('d-m-Y' , strtotime($fields['tanggal_akhir']) ) , "Tanggal"  );
	$view .= form_field_display(  $fields['status'].' '.$fields['tujuan'] , "Status &amp; Tujuan"  );
	if(trim($fields['keperluan']) <> '' )
	$view .= form_field_display(  nl2br($fields['keperluan']) , "Keperluan"  ); 
	$view .= form_footer( );
	$view .= '<form method="POST"><br/><b>Ketentuan tunjangan :</b>';
	
	$header = array(
		'Komponen'=>array('style'=>'border-bottom:2px solid;width:30%'), 
		'Hari'=>array('style'=>'text-align:center;border-bottom:2px solid;width:10%'), 
		'Nominal'=>array('style'=>'text-align:center;border-bottom:2px solid;width:17%'),   
		'Jml'=>array('style'=>'text-align:center;border-bottom:2px solid;width:6%'),   
		'Tunjangan'=>array('style'=>'text-align:center;border-bottom:2px solid;width:17%'),   
		'Adjustment'=>array('style'=>'text-align:center;border-bottom:2px solid;width:20%'),  
	);
	
	$query = "
		SELECT * FROM spd_biaya a 
		INNER JOIN spd_biaya_golongan_jabatan b ON a.biaya_id = b.biaya_id 
		WHERE b.golongan_jabatan_id = {$karyawan['golongan_jabatan_id']}
		";
	$result = my_query($query);
	$row = array();
	$total_tunjangan = 0;
	while($ey = my_fetch_array($result)){
		$hari_penyesuaian = 1 + (int) $ey['penyesuaian_hari'] + (int) selisih_hari( $fields['tanggal_akhir'], $fields['tanggal_mulai'] );
		if( $ey['durasi_hitung'] == 'N' ){
			$hari_penyesuaian = '1';
		}
		
		$nominal_tunjangan = $ey['nominal'] * $hari_penyesuaian;
		$form_adjustment = '<input class="calc" type="text" style="text-align:right;" size="15" value="'.$nominal_tunjangan.'" name="biaya['.$ey['biaya_id'].']"';
		$qty_form = '<input class="ty" type="text" style="text-align:center;" size="3" value="'.$hari_penyesuaian.'" name="qty['.$ey['biaya_id'].']"';
		$row[] = array(
			'komponen'=>$ey['label_biaya'],
			'ahri'=> position_text_align($hari_penyesuaian,'center'),
			'nominal'=>position_text_align('Rp. '.rp_format($ey['nominal']),'right'),
			'qty'=> position_text_align($qty_form,'center'),
			'tunjangan'=>position_text_align('Rp. '.rp_format($nominal_tunjangan),'right'),
			'adjs'=>$form_adjustment,
		);
		$total_tunjangan +=$nominal_tunjangan;
	}
 
	$datas = table_rows($row);
	$view .= table_builder($header , $datas ,  15 ,false  );
	$view .= '<b>Total tunjangan :</b> Rp. <span style="font-size:18px" id="total_tunjangan">'.rp_format($total_tunjangan).'</span>';
	
	$form_again ='<br/><input type="checkbox" name="create_again" value="1" />'; 
	$view .=  $form_again  . " Munculkan formulir lagi";
	
	$view .= '<br/><br/><input type="submit" value="Submit" class="main_button" /></form>';
	return $view; 
}


function selisih_hari(  $date_start , $date_end){  
	$a = new DateTime($date_start." 00:00:00" );
	$b = new DateTime($date_end." 00:00:00" );
	$interval = $a->diff($b);
	if(  $a > $b){
		return    $interval->format("%d")  ;
	}else
		{  
			$interval = $b->diff($a);
			return (-1) *    $interval->format("%d")   ;
		}
}

function submit_biaya(){
	$id = isset($_GET['id']) ? (int) $_GET['id'] : 0  ;
	if(is_array($_POST['biaya'])){
		$biaya_nominal = 0;
		my_query("DELETE FROM spd_simple_biaya WHERE spd_simple_id = {$id} ");
		foreach($_POST['biaya'] as $biaya_id=>$biaya_nominal){
			if((int) $biaya_nominal == 0)continue;
			if((int) $_POST['qty'][$biaya_id] == 0)continue;
			$datas = array(
				'biaya_id'=>my_type_data_int($biaya_id),
				'spd_simple_id'=>my_type_data_int($id),
				'qty'=>my_type_data_int($_POST['qty'][$biaya_id]),
				'nominal'=>my_type_data_int($biaya_nominal),
			);
			my_insert_record('spd_simple_biaya_non_karyawan' , $datas);
			$total_nominal += $biaya_nominal;
		}
	}
	$query = "UPDATE spd_simple_non_karyawan SET biaya = '{$total_nominal}' WHERE spd_simple_id = {$id}";
	return my_query($query);
}


function print_out($spd_id){
	$datas = my_get_data_by_id('spd_simple_non_karyawan' , 'spd_simple_id' , $spd_id);
	
	if($datas['tanggal_mulai'] <> $datas['tanggal_akhir']){
		$nhari = selisih_hari( $datas['tanggal_akhir'],  $datas['tanggal_mulai'] );
		$tanggal = date('d-m-Y' , strtotime( $datas['tanggal_mulai']) ).' ~ '.  date('d-m-Y' , strtotime( $datas['tanggal_akhir']) ) .'( '.$nhari.' hari )';
	}else{
		$tanggal = date('d-m-Y' , strtotime( $datas['tanggal_mulai']) );
	}
	
	$karyawan = my_get_data_by_id( 'spd_non_karyawan','non_karyawan_id',$datas['karyawan_id'] ); 
	$jabatan  =  ( $karyawan['jabatan_non_karyawan'] ); 
	$goljab = my_get_data_by_id('golongan_jabatan' , 'golongan_jabatan_id' , $karyawan['golongan_jabatan_id']);
	$view = '
	<html>
	<head>
		<title>Laporan SPD</title>
		<style>
			td{
				font-family: helvetica;
				
			}
		</style>
	</head>
	<body style="font-size:11px">
	<div style="float:left;width:360px;">cc</div>
	<div style="padding:0 0 0 12px;float:left;">
	<span style="font:14px verdana">BUKTI PEMBAYARAN <br/>PERJALANAN DINAS NON ORGANIK</span><br/> <br/>
	<pre style="margin-bottom:-5px;">
<b>Nomor     : '.$datas['nomor'].'</b>     Cetak :'.date('d-m-Y H:i').'
<b>Pengajuan : '.date('d-m-Y' , strtotime( $datas['tanggal_pengajuan']) ).'</b>

<u>Dibayarkan kepada</u>
NID         : '.$karyawan['nid'].'
Nama	    : '.$karyawan['nama'].' 
Golongan    : '.$goljab['kode_golongan_jabatan'].'

<u>sebagai penggunaan biaya perjalanan</u>
Tempat/ Tujuan  : '.$datas['tujuan'].'
Keperluan       : '.$datas['keperluan'].'
Tanggal         : '. $tanggal.'
	</pre><b>Ketentuan tunjangan :</b>';
	$query = "SELECT * FROM spd_simple_biaya_non_karyawan 
		WHERE spd_simple_id = {$spd_id}   ";
	$result = my_query($query);
	$tdg = my_num_rows($result);
	 
	if($tdg > 0){
/*	
	
	$view .= '<table border="0" width="350px" cellspacing="0" cellpadding="4">
			<tr style="border-bottom:2px solid">
				<td style="border-top:1px solid;border-bottom:2px solid;font-size:11px;" width="40%"><b>Komponen biaya</b></td> 
				<td style="border-top:1px solid;border-bottom:2px solid;font-size:11px;text-align:right;" width="25%"><b>Tarif</b></td> 
				<td style="border-top:1px solid;border-bottom:2px solid;text-align:center;font-size:11px;" width="10%"><b>Jumlah</b></td> 
				<td style="border-top:1px solid;border-bottom:2px solid;text-align:right;font-size:11px;" width="25%"><b>Dibayar</b></td> 
			<tr>';
*/
		$view .= '<pre style="width:38	0px;border-bottom:1px solid;border-top:1px solid;">'."\n";
		$view .= 'KOMPONEN BIAYA           TARIF          JML   DIBAYAR      '."\n";
		$view .= '</pre>'."\n";
		$view .= '<pre style="width:360px;">'."\n";
		
		
	$i=0;
		
		$nominal ='';
	while( $ey = my_fetch_array($result)){
			$biaya_datas = my_get_data_by_id('spd_biaya' , 'biaya_id' , $ey['biaya_id']);
			
			$quersy =  "SELECT nominal FROM spd_biaya_golongan_jabatan WHERE biaya_id = {$ey['biaya_id']} AND golongan_jabatan_id = {$karyawan['golongan_jabatan_id']}";
			$ress = my_query($quersy);
			$rows = my_fetch_array($ress);
			
			$hari_penyesuaian = (int) $ey['qty'] ; 
			$nominal_tunjangan = $ey['nominal'];	
			$nominal += $nominal_tunjangan;
			$i++;
			
			$view .= str_pad( substr( $biaya_datas['label_biaya'] ,0, 22) ,25);
			$view .= 'Rp.  '.str_pad( rp_format( round($nominal_tunjangan/$hari_penyesuaian) ) ,8 ," ",STR_PAD_LEFT);
			$view .= '   '.str_pad(  $hari_penyesuaian ,5);
			$view .= 'Rp.  '.str_pad( rp_format( $nominal_tunjangan ) ,8 ," ",STR_PAD_LEFT)."\n";
			  
	}
	$view .= str_pad( '' ,59 ,"_")."\n";
	$view .= 'Total biaya '.str_pad( 'Rp.'  ,36 ," ",STR_PAD_LEFT).str_pad(  rp_format( $nominal  ) ,11," ",STR_PAD_LEFT)."\n";
	 
	$view .= '</pre>'."\n";
	$view .= '<pre>Terbilang : 
'.fterbilang($nominal).'

HRIS RSKM(C)'.date('Y').'</pre>';
	}
	
	$view .='
	
	
	
	</div>
	</body>
	</html>
	';
	return $view; 
}